package com.yuyou.fn.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.wens.mybatisplus.plugins.Page;
import com.google.common.collect.Maps;
import com.yuyou.fn.common.exception.BusException;
import com.yuyou.fn.common.service.ISiteConfigService;
import com.yuyou.fn.common.service.ISmsService;
import com.yuyou.fn.common.util.BeanUtils;
import com.yuyou.fn.common.util.TimeUtils;
import com.yuyou.fn.educational.entity.Campus;
import com.yuyou.fn.educational.entity.Room;
import com.yuyou.fn.educational.entity.Teacher;
import com.yuyou.fn.educational.service.ICampusService;
import com.yuyou.fn.educational.service.IRoomService;
import com.yuyou.fn.educational.vo.CampusSaveOrUpdateVo;
import com.yuyou.fn.educational.vo.RoomSaveOrUpdateVo;
import com.yuyou.fn.platform.entity.AreaTeam;
import com.yuyou.fn.platform.entity.BusTeam;
import com.yuyou.fn.platform.entity.SysUser;
import com.yuyou.fn.platform.service.*;
import com.yuyou.fn.platform.vo.SysUserSaveOrUpdateVo;
import com.yuyou.fn.settlement.entity.MainAccount;
import com.yuyou.fn.settlement.service.IMainAccountService;
import com.yuyou.fn.tradingservice.entity.*;
import com.yuyou.fn.tradingservice.service.*;
import com.yuyou.fn.tradingservice.vo.*;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;

/**
 * Created by lzh on 2017/5/31.
 */
@Controller
@RequestMapping("/api/service")
public class ServiceApiController extends ApiBaseController{
    @Resource
    private IServiceMerchantService serviceMerchantService;

    @Resource
    private ISmsService smsService;

    @Resource
    private ISysUserService sysUserService;

    @Resource
    private IAccessTokenService accessTokenService;

    @Resource
    private ICaptchaService captchaService;

    @Resource
    private IServiceOrderItemService serviceOrderItemService;

    @Resource
    private IServiceProductService serviceProductService;

    @Resource
    private IServiceCategoryService serviceCategoryService;

    @Resource
    private ILeaseMessageService leaseMessageService;


    @Resource
    private IShippingAddressService shippingAddressService;

    @Resource
    private IServiceOrderService serviceOrderService;

    @Resource
    private ICampusService campusService;

    @Resource
    private IRoomService roomService;

    @Resource
    private IServiceCommentService serviceCommentService;


    @Resource
    private IAreaTeamService areaTeamService;

    @Resource
    private IMainAccountService mainAccountService;

    @Resource
    private IBusTeamService busTeamService;

    @Resource
    private IServiceProductListingService serviceProductListingService;

    @Resource
    private IPersonLeaseMessageService personLeaseMessageService;

    @Resource
    private RedisTemplate redisTemplate;

    @Resource
    private ISiteConfigService siteConfigService;

    @ApiOperation("获得区域列表")
    @RequestMapping(value = "findAllAreaTeam", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<AreaTeam>> findAllAreaTeam(HttpServletRequest request) {
        List<AreaTeam> areaTeamList = areaTeamService.findAllAreaTeam();
        return ReturnResult.success(areaTeamList);
    }


    @ApiOperation("账号密码登陆")
    @RequestMapping(value = "login", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<SysUserLoginSuccessVo> login(@RequestParam(value = "username") String username, @RequestParam("password") String password, @RequestParam(value = "captchaCode", required = false) String captchaCode, @RequestParam(value = "u", required = false) String uid,HttpServletRequest request, HttpSession session) {
        if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
            return ReturnResult.fail("用户名和密码不能为空");
        }
        SysUser user = sysUserService.login(username, password);
        if (user == null) {
            Long failTime = captchaService.opsStat(username, "login");
            HashMap<String, Object> ret = Maps.newHashMap();
            ret.put("failTime", failTime);
            return ReturnResult.fail("用户名或密码不正确", ret);
        }
        if (user.getStatus() == 0) {
            return ReturnResult.fail("你的帐号被禁用，暂时不能登录");
        }

        /*登录查找是否自动注册为商家*/
        ServiceMerchant serviceMerchant = serviceMerchantService.findById(user.getUserId());
        if (serviceMerchant == null) {
            serviceMerchant = new ServiceMerchant();
            BeanUtils.copyProperties(serviceMerchant, user);
            serviceMerchant.setMerchantId(user.getUserId());
            serviceMerchant.setMerchantName(user.getUsername());
            serviceMerchant.setMerchantPassword(user.getPassword());
            serviceMerchant.setHeadImageUrl(user.getAvatarUrl());
            serviceMerchant.setCreateTime(TimeUtils.now());
            serviceMerchant.setUpdateTime(TimeUtils.now());
            serviceMerchant.setStatus(3);//已有用户不需审核
            serviceMerchant.setRoleType(user.getUserType());
            serviceMerchantService.insertSelective(serviceMerchant);
        }

        if (captchaService.needVerifyCode(username, "login", 3)) {
            captchaService.verifyCode(captchaCode);
            captchaService.cleanOptStat(username, "login");
        }
        String accessToken = accessTokenService.generateToken(user.getUserId() ,user.getRealName(),"sysUser" );
        return ReturnResult.success(new SysUserLoginSuccessVo(accessToken, user));
    }

    @ApiOperation("通过手机验证码修改密码")
    @RequestMapping(value = "/changePasswordByCode", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<String> changePasswordByCode(@RequestParam(value = "code") String code, @RequestParam(value = "phoneNo") String phoneNo, @RequestParam(value = "newPasswordMd5") String newPasswordMd5, HttpServletRequest request) {
        //serviceMerchantService.auditMerchants(merchantIds,status);
        boolean ok = smsService.validate(phoneNo, code);
        if (ok) {
            serviceMerchantService.changeMerchantPassword(phoneNo, newPasswordMd5);
        } else {
            return ReturnResult.fail("短信验证码不正确");
        }
        return ReturnResult.success("ok");
    }

    @ApiOperation("修改密码")
    @RequestMapping(value = "/n/changePassword", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> changeMyPassword(@RequestParam("oldPassword") String oldPassword, @RequestParam("newPassword") String newPassword, HttpServletRequest request) {
        SysUser user = getUser(request);
        sysUserService.changePassword(user.getUserId(), oldPassword, newPassword);

        return ReturnResult.success("OK");
    }



    @ApiOperation("检测手机号码是否已被注册")
    @RequestMapping(value = "/checkPhoneNo", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<String> checkPhoneNo(@RequestParam(value = "phoneNo") String phoneNo, HttpServletRequest request) {
        //serviceMerchantService.auditMerchants(merchantIds,status);
        SysUser sysUser = sysUserService.findByPhoneNo(phoneNo);
        if (sysUser != null) {
            return ReturnResult.fail("该手机号码已经注册");
        }
        return ReturnResult.success("ok");
    }


    @ApiOperation("注册")
    @RequestMapping(value = "/register", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<String> register(@ApiParam(value = "手机验证码", required = true) @RequestParam(value = "code") String code, @ModelAttribute ServiceMerchantVo serviceMerchantvo, HttpServletRequest request,
                                         HttpSession session) {
        if (serviceMerchantvo.getRoleType() == null || StringUtils.isEmpty(serviceMerchantvo.getPhoneNo()) || StringUtils.isEmpty(serviceMerchantvo.getMerchantPassword()) || StringUtils.isEmpty(serviceMerchantvo.getMerchantName())) {
            return ReturnResult.fail("缺乏必填参数");
        }
        boolean ok = smsService.validate(serviceMerchantvo.getPhoneNo(), code);
        if (ok) {

            SysUser user = sysUserService.findByUserName(serviceMerchantvo.getMerchantName());


            if (user != null) {
                return ReturnResult.fail("该用户名已经存在，请直接登录");
            }

            Long count=serviceMerchantService.countByPhoneNoAndStatus(serviceMerchantvo.getPhoneNo(),0);
            if (count>0){
                return ReturnResult.fail("该手机号存在待审核的商家，不可重复提交");
            }
            SysUser sysUser=sysUserService.findByPhoneNo(serviceMerchantvo.getPhoneNo());
            if (sysUser!=null){
                return ReturnResult.fail("该手机号已存在用户，不可注册");
            }
            if (serviceMerchantvo.getRoleType() == 2) {//业务组检查名称是否存在
                BusTeam busTeam = busTeamService.findByAreaTeamIdAndBusName(serviceMerchantvo.getBelongAreaTeamId(), serviceMerchantvo.getBelongBusTeamName());
                if (busTeam != null) {
                    throw new BusException("该业务组名称已存在，注册申请失败");
                }
            }
            if (serviceMerchantvo.getRoleType() == 3) {//业务组检查名称是否存在
                Teacher teacher =teacherService.findTeacherByIdNo(serviceMerchantvo.getIdNo());
                //BusTeam busTeam = busTeamService.findByAreaTeamIdAndBusName(serviceMerchantvo.getBelongAreaTeamId(), serviceMerchantvo.getBelongBusTeamName());
                if (teacher != null) {
                    throw new BusException("该身份证已存在，注册申请失败");
                }
            }

            serviceMerchantvo.setStatus(0);//新注册未审核
            serviceMerchantService.save(serviceMerchantvo);
            return ReturnResult.success("注册提交成功，请等待管理员审核，谢谢！");
        } else {
            return ReturnResult.fail("验证码校验失败");
        }
    }

    @ApiOperation("分类，发布区域，收款主体")
    @RequestMapping(value = "/allConfig", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Object> allConfig(HttpServletRequest request) {


        HashMap<String,Object> result=new HashMap<String,Object>(3);

        List<AreaTeam> areaTeamList = areaTeamService.findAllAreaTeam();
        List<ServiceCategoryTreeVo> goodsCategoryList = serviceCategoryService.findServiceCategoryTreeVoByType(0);

        List<ServiceCategoryTreeVo> leaseCategoryList = serviceCategoryService.findServiceCategoryTreeVoByType(2);

        List<ServiceCategoryTreeVo> demandCategoryList = serviceCategoryService.findServiceCategoryTreeVoByType(3);
        result.put("areaTeamList",areaTeamList);
        result.put("goodsCategoryList",goodsCategoryList);
        result.put("leaseCategoryList",leaseCategoryList);
        result.put("demandCategoryList",demandCategoryList);


        return ReturnResult.success(result);
    }


    @ApiOperation("用户可选的区域或业务组")
    @RequestMapping(value = "/n/ownTeam", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<TeamVo>> ownTeam(HttpServletRequest request) {
        SysUser user = getUser(request);
        List<TeamVo> teamVoList=serviceMerchantService.ownTeam(user);
        return ReturnResult.success(teamVoList);
    }



    @ApiOperation("用户可选的主体")
    @RequestMapping(value = "/n/ownMainCount", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<MainAccount>> ownMainCount(HttpServletRequest request) {
        SysUser user = getUser(request);
        List<MainAccount> mainAccountList = serviceMerchantService.ownMainAccount(user);
        return ReturnResult.success(mainAccountList);
    }

    @ApiOperation("租赁时用户可选的校区课室")
    @RequestMapping(value = "/n/ownPlace", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Map<Long,Object>> ownPlace(HttpServletRequest request) {
        SysUser user = getUser(request);
        Map<Long,Object>  map=serviceProductService.findOwnPlaceList(user);
        return ReturnResult.success(map);
    }

    @ApiOperation("退出")
    @RequestMapping(value = "/logout", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<String> logout(HttpServletRequest request) {
        request.getSession().removeAttribute("user");
        request.getSession().removeAttribute("accessToken");
        return ReturnResult.success("ok");
    }

    @ApiOperation("清单和订单数量")
    @RequestMapping(value = "/n/cartNumAndOrderNum", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<HashMap<String, Long>> cartNumAndOrderNum(HttpServletRequest request) {

        HashMap<String, Long> resultMap = new HashMap<String, Long>();
        resultMap.put("listingNum", 0L);
        resultMap.put("orderNum", 0L);
        SysUser user = getUser(request);
        Long listingNum = serviceProductListingService.countByBuyerId(user.getUserId());//serviceCartItemService.countCartItemNumByUserId(user.getUserId());
        Long orderNum = serviceOrderItemService.countOrderNumByUserId(user.getUserId());
        resultMap.put("listingNum", listingNum);
        resultMap.put("orderNum", orderNum);
        return ReturnResult.success(resultMap);
    }

    @ApiOperation("首页轮播图和最新产品")
    @RequestMapping(value = "/indexData", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<HashMap<String, Object>> indexData(@RequestParam(value = "goodsLimit", defaultValue = "8") Integer goodsLimit,@RequestParam(value = "leaseLimit", defaultValue = "4") Integer leaseLimit,  HttpServletRequest request) throws IOException {
        HashMap<String, Object> resultMap = new HashMap<String, Object>();
        String configJSON = siteConfigService.getConfigValueFromCache("service_index_config");
        JSONObject config = JSONObject.parseObject(configJSON);
        JSONArray jsonArray = config.getJSONArray("indexPicture");
        ProductQueryVo productQueryVo=new ProductQueryVo();
        productQueryVo.setStatus(1);
        productQueryVo.setType(0);
        Page<ServiceProduct> goodsPage= serviceProductService.findProductPageByQueryVo(productQueryVo,1,goodsLimit);
        productQueryVo.setType(2);

        Page<ServiceProduct> serviceLeaseProductPage=serviceProductService.findProductPageByQueryVo(productQueryVo,1,leaseLimit);
        resultMap.put("serviceLeaseProductList",serviceLeaseProductPage.getRecords());


        resultMap.put("indexPicture", jsonArray);
        // resultMap.put("serviceProductList", serviceProductList);
        resultMap.put("goodsList", goodsPage.getRecords());

        //resultMap.put("leasePage",leasePage);
        return ReturnResult.success(resultMap);
    }



    @ApiOperation("分类信息")
    @RequestMapping(value = "/category", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ServiceCategory>> category(@RequestParam(value = "type") Integer type, HttpServletRequest request) throws IOException {
        List<ServiceCategory> serviceCategoryList = serviceCategoryService.findListByType(type);
        return ReturnResult.success(serviceCategoryList);
    }

    @ApiOperation("新建商品")
    @RequestMapping(value = "/n/addProduct", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> addProduct(@ModelAttribute ProductVo productVo, HttpServletRequest request) {
        SysUser user = getUser(request);
        //serviceProductService.saveServiceProduct(null,user,productVo,productImages);
        serviceProductService.saveOrUpdateGoods(productVo, user);
        return ReturnResult.success("ok");
    }

    @ApiOperation("修改商品")
    @RequestMapping(value = "/n/updateProduct", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> updateProduct(@ModelAttribute ProductVo productVo, HttpServletRequest request) {
        SysUser user = getUser(request);
        if (productVo.getProductId() == null) {
            return ReturnResult.fail("请传入商品id");
        }
        serviceProductService.saveOrUpdateGoods(productVo, user);
        return ReturnResult.success("ok");
    }
    @ApiOperation("新增需求")
    @RequestMapping(value = "/n/addDemand", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> addDemand(@RequestParam(value = "type",defaultValue = "3") Integer type,@ModelAttribute DemandVo demandVo, HttpServletRequest request) {
        SysUser user = getUser(request);

        serviceProductService.saveOrUpdateDemand(demandVo, user);
        return ReturnResult.success("ok");
    }

    @ApiOperation("需求详情")
    @RequestMapping(value = "/demandDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<ServiceProduct> demandDetail(@RequestParam(value = "path",defaultValue = "0")Integer path,@RequestParam(value = "productId") Long productId, HttpServletRequest request) {
        ServiceProduct serviceProduct=serviceProductService.findById(productId);
        if (path==0 &&(serviceProduct == null || serviceProduct.getStatus() == 0)) {
            return ReturnResult.fail("需求不存在或者已下架");
        }

        return ReturnResult.success(serviceProduct);
    }

    @ApiOperation("修改需求")
    @RequestMapping(value = "/n/changeDemand", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> changeDemand(@ModelAttribute DemandVo demandVo,HttpServletRequest request) {
        SysUser user = getUser(request);
        if (demandVo.getProductId() == null) {
            return ReturnResult.fail("请传入需求id");
        }
        serviceProductService.saveOrUpdateDemand(demandVo, user);
        return ReturnResult.success("ok");
    }



    @ApiOperation("新建或者更新租赁")
    @RequestMapping(value = "/n/addLeaseProduct", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> addLeaseProduct(@RequestParam(value = "type",defaultValue = "2") Integer type,@RequestParam(value = "leaseMessageListJson", defaultValue = "") String leaseMessageListJson, @ModelAttribute LeaseVo leaseVo,  HttpServletRequest request) {
        SysUser user = getUser(request);
        List<LeaseMessagePriceVo> leaseMessagePriceVoList = null;
        if (StringUtils.isNotEmpty(leaseMessageListJson)) {
            leaseMessagePriceVoList = JSONObject.parseArray(leaseMessageListJson, LeaseMessagePriceVo.class);
        } else {
            return ReturnResult.fail("缺少租赁信息");
        }
        serviceProductService.saveLeaseProduct( leaseVo, user,leaseMessagePriceVoList);

        return ReturnResult.success("ok");
    }


    @ApiOperation("上架下架")
    @RequestMapping(value = "/n/onOrOff", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> onOrOff(@RequestParam(value = "productId") Long productId, @RequestParam(value = "status") Integer status, HttpServletRequest request) {
        SysUser user = getUser(request);
        serviceProductService.onOrOff(user, productId, status,1);
        return ReturnResult.success("Ok");
    }


    @ApiOperation("商品删除")
    @RequestMapping(value = "/n/deleteGoods", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> deleteGoods(@RequestParam(value = "productIds[]") List<Long> productIds, HttpServletRequest request) {
        SysUser user = getUser(request);
        serviceProductService.deleteProductByUserIdAndProductId(user.getUserId(), productIds,1);
        return ReturnResult.success("Ok");
    }

    @ApiOperation("需求删除")
    @RequestMapping(value = "/n/deleteDemand", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> deleteDemand(@RequestParam(value = "productIds[]") List<Long> productIds, HttpServletRequest request) {
        SysUser user = getUser(request);
        serviceProductService.deleteProductByUserIdAndProductId(user.getUserId(), productIds,1);
        return ReturnResult.success("Ok");
    }


    @ApiOperation("租赁删除")
    @RequestMapping(value = "/n/deleteLeaseProduct", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> deleteLeaseMessage(@RequestParam(value = "productIds[]") List<Long> productIds, HttpServletRequest request) {
        SysUser user = getUser(request);
        serviceProductService.deleteProductByUserIdAndProductId(user.getUserId(), productIds,1);
        return ReturnResult.success("Ok");
    }



    @ApiOperation("商品列表")
    @RequestMapping(value = "/goodPage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ServiceProduct>> goodPage(@RequestParam(value = "type", defaultValue = "0") Integer type, @RequestParam(value = "pageNo") int pageNo, @RequestParam(value = "pageSize") int pageSize, @ModelAttribute ProductQueryVo productQueryVo, HttpServletRequest request) {
        productQueryVo.setType(type);
        productQueryVo.setStatus(1);
        Page<ServiceProduct> serviceProductPage = serviceProductService.findProductPageByQueryVo(productQueryVo, pageNo, pageSize);
        return ReturnResult.success(serviceProductPage);
    }

    @ApiOperation("需求列表")
    @RequestMapping(value = "/demandPage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ServiceProduct>> demandPage(@RequestParam(value = "type", defaultValue = "3") Integer type, @RequestParam(value = "pageNo") int pageNo, @RequestParam(value = "pageSize") int pageSize, @ModelAttribute ProductQueryVo productQueryVo, HttpServletRequest request) {
        productQueryVo.setType(type);
        productQueryVo.setStatus(1);
        Page<ServiceProduct> serviceProductPage = serviceProductService.findProductPageByQueryVo(productQueryVo, pageNo, pageSize);
        return ReturnResult.success(serviceProductPage);
    }


    @ApiOperation("租赁列表")
    @RequestMapping(value = "/leasePage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ServiceProduct>> leasePage(@RequestParam(value = "type", defaultValue = "2") Integer type, @RequestParam(value = "pageNo") int pageNo, @RequestParam(value = "pageSize") int pageSize, @ModelAttribute  ProductQueryVo productQueryVo, HttpServletRequest request) {

        productQueryVo.setType(type);
        productQueryVo.setStatus(1);
        Page<ServiceProduct> serviceProductPage=serviceProductService.findProductPageByQueryVo(productQueryVo, pageNo, pageSize);
        return ReturnResult.success(serviceProductPage);
    }


    @ApiOperation("商品详情")
    @RequestMapping(value = "/goodDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<ServiceProduct> goodDetail(@RequestParam(value = "path",defaultValue = "0")Integer path,@RequestParam(value = "productId") Long productId, HttpServletRequest request) {
        ServiceProduct serviceProduct = serviceProductService.findById(productId);
        if (path==0 &&(serviceProduct == null || serviceProduct.getStatus() == 0)) {
            return ReturnResult.fail("商品不存在或者已下架");
        }
        return ReturnResult.success(serviceProduct);
    }


    @ApiOperation("租赁详情")
    @RequestMapping(value = "/leaseAllTimeDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<ServiceLeaseProductDetail> leaseAllTimeDetail(@RequestParam(value = "path",defaultValue = "0")Integer path,@RequestParam(value = "productId") Long productId, HttpServletRequest request) {
        ServiceLeaseProductDetail serviceLeaseProductDetail=serviceProductService.leaseProductDetail(productId,path);
        return ReturnResult.success(serviceLeaseProductDetail);
    }


    @ApiOperation("添加评论")
    @RequestMapping(value = "/n/addProductComment", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<String> addProductComment(@ModelAttribute ServiceCommentVo serviceCommentVo, HttpServletRequest request) {
        //Page<ServiceComment> serviceCommentPage=serviceCommentService.findPageComment(productId,pageNo,pageSize);
        SysUser user = getUser(request);
        serviceCommentService.addComment(serviceCommentVo, user);
        return ReturnResult.success("ok");
    }


    @ApiOperation("获得评论")
    @RequestMapping(value = "/productCommentList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ServiceComment>> productCommentList(@RequestParam(value = "pageNo", required = false, defaultValue = "1") int pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize, @RequestParam(value = "productId") Long productId, HttpServletRequest request) {
        Page<ServiceComment> serviceCommentPage = serviceCommentService.findPageComment(productId, pageNo, pageSize);
        return ReturnResult.success(serviceCommentPage);
    }

    @ApiModelProperty("检测租赁购物车是否失效")
    @RequestMapping(value = "/checkLeaseListing", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> checkLeaseListing(@RequestParam(value = "listingIds[]") List<Long> listingIds, HttpServletRequest request) {
        serviceProductListingService.checkLeaseListingByIds(listingIds,0);
        return ReturnResult.success("ok");
    }

    @ApiOperation("商品加入清单")
    @RequestMapping(value = "/n/addGoodToListing", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Long> addGoodToListing(HttpServletRequest request, @RequestParam(value = "productId") Long productId, @RequestParam(value = "quantity") int quantity) {
        SysUser user = getUser(request);
        serviceProductListingService.addGoodToListing(user, productId, quantity,1);
        return ReturnResult.success("ok");
    }

    @ApiOperation("检测用户是否已经发布过该课室的租赁信息")
    @RequestMapping(value = "/n/checkIfRelease", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Long> checkIfRelease(HttpServletRequest request,@RequestParam(value = "profitMainAccountId")long profitMainAccountId,@RequestParam(value = "roomId") Long roomId) {
        SysUser user = getUser(request);
        serviceProductService.checkIfRelease(user.getUserId(),roomId,profitMainAccountId);
        return ReturnResult.success("ok");
    }


    @ApiOperation("商品立即购买提交订单")
    @RequestMapping(value = "/n/buyGoodsImmediately", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<ServiceOrder> buyGoods(HttpServletRequest request,@RequestParam("payMainAccountId")Long payMainAccountId,@RequestParam("addressId")Long addressId, @RequestParam(value = "productId") Long productId, @RequestParam(value = "quantity") int quantity) {
        SysUser user = getUser(request);

        ServiceOrder serviceOrder=serviceOrderService.createGoodsOrderByBuyImmediately(user,productId,quantity,payMainAccountId,addressId);
        return ReturnResult.success(serviceOrder);
    }




    @ApiOperation("判断租赁时间是否可租，计算总价")
    @RequestMapping(value = "/n/findPersonLeaseTime", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<PersonLeaseResultVo> findPersonLeaseTime(@ModelAttribute PersonLeaseSearchVo personLeaseSearchVo, HttpServletRequest request) {
        SysUser user = getUser(request);
        PersonLeaseResultVo personLeaseResultVo=personLeaseMessageService.findPersonLeaseTime(user,personLeaseSearchVo);
        return ReturnResult.success(personLeaseResultVo);
    }




    @ApiOperation("租赁加入清单")
    @RequestMapping(value = "/n/addLeaseToListing", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<String> addLeaseToListing(@RequestParam(value = "personLeaseMessageListJson", defaultValue = "") String personLeaseMessageListJson, HttpServletRequest request,@RequestParam(value = "productId") Long productId) {
        SysUser user = getUser(request);

        List<PersonLeaseMessage> personLeaseMessageList = null;
        if (StringUtils.isNotEmpty(personLeaseMessageListJson)) {
            personLeaseMessageList = JSONObject.parseArray(personLeaseMessageListJson, PersonLeaseMessage.class);
        }
        if (personLeaseMessageList == null) {
            return ReturnResult.fail("缺少租赁信息");
        }
        serviceProductListingService.addLeaseToListing(1,user, productId, personLeaseMessageList,1);
        return ReturnResult.success("ok");
    }

    @ApiOperation("租赁立即购买提交订单")
    @RequestMapping(value = "/n/buyLeaseImmediately", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<ServiceOrder> buyLeaseImmediately(@RequestParam(value = "personLeaseMessageListJson", defaultValue = "") String personLeaseMessageListJson, HttpServletRequest request, @RequestParam("payMainAccountId")Long payMainAccountId,@RequestParam("addressId")Long addressId, @RequestParam(value = "productId") Long productId) {
        SysUser user = getUser(request);
        List<PersonLeaseMessage> personLeaseMessageList = null;
        if (StringUtils.isNotEmpty(personLeaseMessageListJson)) {
            personLeaseMessageList = JSONObject.parseArray(personLeaseMessageListJson, PersonLeaseMessage.class);
        }
        if (personLeaseMessageList == null) {
            return ReturnResult.fail("缺少租赁信息");
        }
        ServiceOrder serviceOrder=serviceOrderService.createLeaseOrderByBuyImmediately(personLeaseMessageList,user,productId,payMainAccountId,addressId);
        return ReturnResult.success(serviceOrder);
    }




    @ApiOperation("修改清单中商品数量")
    @RequestMapping(value = "/n/updateListingQuantity", method = {RequestMethod.POST})
    @ResponseBody
    public ReturnResult<String> updateListingQuantity(@RequestParam(value = "listingId") Long listingId, @RequestParam(value = "quantity") int quantity, HttpServletRequest request) {

        serviceProductListingService.updateListingQuantity(listingId, quantity);
        return ReturnResult.success("ok");
    }


    @ApiOperation("删除清单内容")
    @RequestMapping(value = "/n/delListing", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<String> delListing(@RequestParam(value = "way",defaultValue = "0") Integer way,@RequestParam(value = "listingIds[]") List<Long> listingIds, HttpServletRequest request) {
        serviceProductListingService.deleteListingByIds(listingIds,way);
        return ReturnResult.success("ok");
    }




    @ApiOperation("获取地址")
    @RequestMapping(value = "/n/shippingAddressList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ShippingAddress>> shippingAddressList(@RequestParam(value = "pageNo", required = false, defaultValue = "1") int pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize,  HttpServletRequest request) {
        SysUser user = getUser(request);
        List<ShippingAddress> shippingAddressList = shippingAddressService.findAddressListByUserId(user.getUserId());
        return ReturnResult.success(shippingAddressList);
    }

    @ApiOperation("添加或修改收货地址")
    @RequestMapping(value = "/n/saveOrUpdateShippingAddress", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> saveOrUpdateShippingAddress(@ModelAttribute ShippingAddress shippingAddress, HttpServletRequest request) {
        SysUser sysUser = getUser(request);
        shippingAddress.setUserId(sysUser.getUserId());
        shippingAddress.setUserName(sysUser.getRealName());
        shippingAddressService.saveOrUpdateAddress(shippingAddress);
        return ReturnResult.success("ok");
    }

    @ApiOperation("删除收货地址")
    @RequestMapping(value = "/n/deleteShippingAddress", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> deleteShippingAddress(@RequestParam(value = "address_id")Long addressId ,HttpServletRequest request) {
        shippingAddressService.deleteById(addressId);
        return ReturnResult.success("ok");
    }



    @ApiOperation("清单列表")
    @RequestMapping(value = "/n/listingList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ListingDetailVo>> listingList(HttpServletRequest request) {
        SysUser user = getUser(request);
        List<ListingDetailVo> listingDetailVoList=serviceProductListingService.checkAndFind(user.getUserId());
        return ReturnResult.success(listingDetailVoList);
    }



    @ApiOperation("清单提交订单")
    @RequestMapping(value = "/n/submitListing", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<ServiceOrder> submitListing(@RequestParam(value = "pay_main_account_id") Long payMainAccountId,@RequestParam(value = "addressId", defaultValue = "0") Long addressId,
                                                    HttpServletRequest request, @RequestParam(value = "listingIds[]") List<Long> listingIds) {
        //获取当前登录用户
        SysUser user = getUser(request);
        ServiceOrder order = serviceOrderService.createOrder(addressId, user, listingIds,payMainAccountId);
        return ReturnResult.success(order);
    }


    @ApiOperation("系统用户详情")
    @RequestMapping(value = "/n/sysUserDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<SysUser> sysUserDetail(HttpServletRequest request) {
        SysUser user = getUser(request);
        return ReturnResult.success(user);
    }

    @ApiOperation("保存更新系统用户")
    @RequestMapping(value = "/saveOrUpdateSysUser", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<SysUserSaveOrUpdateVo> saveOrUpdateSysUser(SysUserSaveOrUpdateVo sysUserSaveOrUpdateVo, HttpServletRequest request) {
        //sysUserSaveOrUpdateVo.setAreaTeamId(getUser(request).getAreaTeamId());
        SysUser user = getUser(request);
        sysUserSaveOrUpdateVo.setUserId(user.getUserId());
        sysUserSaveOrUpdateVo.setUsername(user.getUsername());
        sysUserService.saveOrUpdateSysUser(sysUserSaveOrUpdateVo);
        return ReturnResult.success("Ok");
    }


    @ApiOperation("出租课室时查看时间占用表")
    @RequestMapping(value = "/n/leaseTimeTable", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<TreeMap<String, List<String>>> leaseTimeTable(@RequestParam(value = "endDate") Date endDate,
                                                                      @RequestParam(value = "startDate") Date startDate,
                                                                      @RequestParam(value = "roomId") Long roomId,
                                                                      @RequestParam(value = "startTime", required = false, defaultValue = "8:00") String start,
                                                                      @RequestParam(value = "endTime", required = false, defaultValue = "22:00") String end,
                                                                      @RequestParam(value = "minutes", required = false,defaultValue = "60") Integer minutes,
                                                                      @RequestParam(value = "profitMainAccountId",required = true) long profitMainAccountId,
                                                                      HttpServletRequest request) {
        SysUser user = getUser(request);
        TreeMap<String, List<String>> stringListHashMap = serviceProductService.findLeaseTimeTable(startDate, endDate, start, end, roomId, user,minutes,profitMainAccountId);
        return ReturnResult.success(stringListHashMap);
    }

    @ApiOperation("租赁课室时查看时间占用表")
    @RequestMapping(value = "/personLeaseTimeTable", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<TreeMap<String, List<String>>> personLeaseTimeTable(@RequestParam(value = "endDate") Date endDate,
                                                                            @RequestParam(value = "startDate") Date startDate,
                                                                            @RequestParam(value = "productId") Long productId,
                                                                            @RequestParam(value = "startTime", required = false, defaultValue = "8:00") String start,
                                                                            @RequestParam(value = "endTime", required = false, defaultValue = "22:00") String end,
                                                                            @RequestParam(value = "minutes", required = false,defaultValue = "60") Integer minutes,
                                                                            HttpServletRequest request) {
       // SysUser user = getUser(request);
        TreeMap<String, List<String>> stringListHashMap = serviceProductService.findPersonLeaseTimeTable(startDate, endDate, start, end, productId, minutes);
        return ReturnResult.success(stringListHashMap);
    }





    @ApiOperation("新建需审核的校区")
    @RequestMapping(value = "/n/saveUnAuditedCampus", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> saveUnAuditedCampus(CampusSaveOrUpdateVo campusSaveOrUpdateVo,HttpServletRequest request) {
        SysUser user = getUser(request);
        campusSaveOrUpdateVo.setUserId(user.getUserId());
        campusSaveOrUpdateVo.setUserPhoneNo(user.getPhoneNo());
        campusSaveOrUpdateVo.setUsername(user.getUsername());

        campusSaveOrUpdateVo.setState(0);

        campusService.saveOrUpdateCampus(campusSaveOrUpdateVo);
        return ReturnResult.success("ok");
    }

    @ApiOperation("编辑校区")
    @RequestMapping(value = "/n/editorCampus", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> editorCampus(CampusSaveOrUpdateVo campusSaveOrUpdateVo,HttpServletRequest request) {
        campusSaveOrUpdateVo.setState(0);
        campusService.updateCampus(campusSaveOrUpdateVo);
        return ReturnResult.success("Ok");
    }

    @ApiOperation("校区列表")
    @RequestMapping(value = "/n/campusList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<Campus>> campusList(CampusSaveOrUpdateVo campusSaveOrUpdateVo,HttpServletRequest request) {
        SysUser user = getUser(request);
        List<Campus> campusList=campusService.findCampusByUserId(user.getUserId(),null);
        return ReturnResult.success(campusList);
    }

    @ApiOperation("校区详情")
    @RequestMapping(value = "/campusDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Campus> campusDetail(@RequestParam(value = "campusId") Long campusId, HttpServletRequest request ) {
        Campus campus=campusService.findById(campusId);
        return ReturnResult.success(campus);
    }





    @ApiOperation("新建教室")
    @RequestMapping(value = "/n/saveUnAuditedRoom", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> saveUnAuditedRoom(RoomSaveOrUpdateVo roomSaveOrUpdateVo,HttpServletRequest request) {
        roomService.saveOrUpdateRoom(roomSaveOrUpdateVo);
        return ReturnResult.success("Ok");
    }

    @ApiOperation("编辑教室")
    @RequestMapping(value = "/n/editorRoom", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> editorRoom(RoomSaveOrUpdateVo roomSaveOrUpdateVo,HttpServletRequest request) {
        roomService.saveOrUpdateRoom(roomSaveOrUpdateVo);
        return ReturnResult.success("Ok");
    }

    @ApiOperation("教室列表")
    @RequestMapping(value = "/n/roomList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<Room>> roomList(@RequestParam(value = "campusId") Long campusId,HttpServletRequest request) {
        List<Room> roomList=roomService.findListByCampusId(campusId,null,null);
        return ReturnResult.success(roomList);
    }

    @ApiOperation("教室详情")
    @RequestMapping(value = "/n/roomDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Room> saveUnAuditedRoom(@RequestParam(value = "roomId") Long roomId, HttpServletRequest request) {
        Room room = roomService.findById(roomId);
        return ReturnResult.success(room);
    }

    @ApiOperation("删除校区")
    @RequestMapping(value = "/n/delCampus", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> delCampus(@RequestParam("campusId") Long campusId,HttpServletRequest request) {

        campusService.deleteCampus(campusId);
        return ReturnResult.success("Ok");
    }

    @ApiOperation("删除教室")
    @RequestMapping(value = "/n/delRoom", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> delRoom(@RequestParam("roomId") Long roomId,HttpServletRequest request) {
        roomService.deleteRoom(roomId);
        return ReturnResult.success("Ok");
    }


    @ApiOperation("我发布的商品")
    @RequestMapping(value = "/n/myPublishGoods", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ServiceProduct>> myPublishGoods(@ModelAttribute ProductQueryVo productQueryVo,@RequestParam(value = "type",defaultValue = "0") Integer type,@RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize, HttpServletRequest request) {
        //roomService.deleteRoom(roomId);
        SysUser user = getUser(request);
        productQueryVo.setType(type);
        productQueryVo.setSellerId(user.getUserId());
        Page<ServiceProduct> serviceProductPage = serviceProductService.findProductPageByQueryVo(productQueryVo, pageNo, pageSize);
        return ReturnResult.success(serviceProductPage);
    }
    @ApiOperation("我发布的租赁")
    @RequestMapping(value = "/n/myPublishLeases", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ServiceLeaseProductDetail>> myPublishLeases(@ModelAttribute ProductQueryVo productQueryVo ,@RequestParam(value = "type",defaultValue = "2") Integer type,@RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize, HttpServletRequest request) {
        //roomService.deleteRoom(roomId);
        SysUser user = getUser(request);
        productQueryVo.setSellerId(user.getUserId());
        Page<ServiceLeaseProductDetail> serviceLeaseProductDetailPage=serviceProductService.findLeaseProductByQueryVo(productQueryVo,pageNo,pageSize);
        return ReturnResult.success(serviceLeaseProductDetailPage);
    }

    @ApiOperation("我发布的需求")
    @RequestMapping(value = "/n/myPublishDemands", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ServiceProduct>> myPublishDemands(@ModelAttribute ProductQueryVo productQueryVo,@RequestParam(value = "type",defaultValue = "3") Integer type,@RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize, HttpServletRequest request) {
        //roomService.deleteRoom(roomId);
        SysUser user = getUser(request);
        productQueryVo.setType(type);
        productQueryVo.setSellerId(user.getUserId());
        Page<ServiceProduct> serviceProductPage = serviceProductService.findProductPageByQueryVo(productQueryVo, pageNo, pageSize);
        return ReturnResult.success(serviceProductPage);
    }


    @ApiOperation("我卖出的")
    @RequestMapping(value = "/n/mySell", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ServiceOrderItemResultVo>> mySell(@ModelAttribute ServiceOrderItemQueryVo serviceOrderItemQueryVo,@RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize, HttpServletRequest request) {
        //roomService.deleteRoom(roomId);
        SysUser user = getUser(request);
        serviceOrderItemQueryVo.setSellerId(user.getUserId());
        Page<ServiceOrderItem> serviceOrderItemPage = serviceOrderItemService.findByQueryCond(serviceOrderItemQueryVo, pageNo, pageSize);
        Page<ServiceOrderItemResultVo> serviceOrderItemResultVoPage=serviceOrderItemService.fillByItemPage(serviceOrderItemPage);
        return ReturnResult.success(serviceOrderItemResultVoPage);
    }

    @ApiOperation("我购买的")
    @RequestMapping(value = "/n/myBuy", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ServiceOrderItemResultVo>> myBuy(@ModelAttribute ServiceOrderItemQueryVo serviceOrderItemQueryVo,@RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize, HttpServletRequest request) {
        SysUser user = getUser(request);
        serviceOrderItemQueryVo.setBuyerId(user.getUserId());
        Page<ServiceOrderItem> serviceOrderItemPage = serviceOrderItemService.findByQueryCond(serviceOrderItemQueryVo, pageNo, pageSize);
        Page<ServiceOrderItemResultVo> serviceOrderItemResultVoPage=serviceOrderItemService.fillByItemPage(serviceOrderItemPage);
        return ReturnResult.success(serviceOrderItemResultVoPage);
    }

    @ApiOperation("订单详情")
    @RequestMapping(value = "/n/orderDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<ServiceOrderItem> orderDetail(@RequestParam(value = "orderItemId")Long orderItemId, HttpServletRequest request) {
        SysUser user = getUser(request);
        ServiceOrderItemQueryVo serviceOrderItemQueryVo = new ServiceOrderItemQueryVo();
        serviceOrderItemQueryVo.setBuyerId(user.getUserId());
        serviceOrderItemQueryVo.setOrderItemId(orderItemId);
        ServiceOrderItem serviceOrderItem = serviceOrderItemService.findByItemId(serviceOrderItemQueryVo.getOrderItemId());
        return ReturnResult.success(serviceOrderItem);
    }

    @ApiOperation("确认发货")
    @RequestMapping(value = "/n/confirmDelivery", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<String> confirmDelivery(@RequestParam(value = "logisticsName",required = false)String logisticsName,@RequestParam(value = "logisticsNo",required = false)String logisticsNo,@RequestParam(value = "goodState",defaultValue = "7") Integer goodState, @RequestParam(value = "orderItemId" )Long orderItemId, HttpServletRequest request) {


        ServiceOrderItem serviceOrderItem=new ServiceOrderItem();
        serviceOrderItem.setOrderItemId(orderItemId);
        serviceOrderItem.setGoodState(goodState);
        serviceOrderItem.setLogisticsName(logisticsName);
        serviceOrderItem.setLogisticsNo(logisticsNo);
        serviceOrderItem.setUpdateTime(TimeUtils.now());
        serviceOrderItem.setOrderStatus(goodState);
        serviceOrderItemService.updateSelectiveById(serviceOrderItem);
        return ReturnResult.success("ok");
    }
    @ApiOperation("确认收货")
    @RequestMapping(value = "/n/confirmGoods", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<String> confirmGoods(@RequestParam(value = "goodState",defaultValue = "8") Integer goodState, @RequestParam(value = "orderItemId" )Long orderItemId, HttpServletRequest request) {
        //Page<ServiceComment> serviceCommentPage=serviceCommentService.findPageComment(productId,pageNo,pageSize);
        //serviceCommentService.addComment(serviceCommentVo, user);
        serviceOrderItemService.changeGoodStateById(orderItemId,goodState);
        return ReturnResult.success("ok");
    }


    @ApiOperation("申请退款")
    @RequestMapping(value = "/n/applyRefund", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<String> applyRefund(@RequestParam(value = "chargingStatus",defaultValue = "6") Integer chargingStatus,@RequestParam(value = "orderItemId" )Long orderItemId,@RequestParam(value = "refundReasonTag",required = false) String refundReasonTag,@RequestParam(value = "refundReason",required = false) String refundReason, HttpServletRequest request) {
        //Page<ServiceComment> serviceCommentPage=serviceCommentService.findPageComment(productId,pageNo,pageSize);
        SysUser user = getUser(request);
        serviceOrderItemService.applyRefund(orderItemId,user,chargingStatus,refundReasonTag,refundReason);

        return ReturnResult.success("ok");
    }

    @ApiOperation("处理退款   0不同意，1同意")
    @RequestMapping(value = "/n/dealRefund", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<String> dealRefund(@RequestParam(value = "status") Integer status,@RequestParam(value = "orderItemId" )Long orderItemId, HttpServletRequest request) {
        //Page<ServiceComment> serviceCommentPage=serviceCommentService.findPageComment(productId,pageNo,pageSize);
        SysUser user = getUser(request);
        serviceOrderItemService.dealRefund(orderItemId,user,status);
        return ReturnResult.success("ok");
    }


    @ApiOperation("余额支付")
    @RequestMapping(value = "/n/balancePayment", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<String> bigBalancePayment(@RequestParam(value = "orderId") Long orderId,@RequestParam(value = "paidAmount") BigDecimal paidAmount,@RequestParam(value = "payWay",defaultValue = "3") Integer payWay, HttpServletRequest request) {
        //Page<ServiceComment> serviceCommentPage=serviceCommentService.findPageComment(productId,pageNo,pageSize);
        payWay = 3;
        serviceOrderService.payServiceOrder(orderId, paidAmount, payWay);
        return ReturnResult.success("ok");
    }


}
